﻿using System.Threading.Tasks;
using AutoMapper;
using Jinjia.Core.BaseInfrastructure.StorageModel;
using Jinjia.Core.BaseInfrastructure.StorageModel.Impl;
using Jinjia.Core.UnitOfWork.UnitOfWorkComponent;
using Jinjia.Approve.Entity.Entity;
using Jinjia.Approve.IRepository;
using Jinjia.Approve.Model.Input;
using Jinjia.Approve.Model.VM;

namespace Jinjia.Approve.Repository
{
    public class HelloWorldBaseRepository : BaseRepository<hello_world_tbl>, IHelloWorldRepository
    {
        private readonly IMapper _mapper;

        public HelloWorldBaseRepository(IUnitOfWork unitOfWork, IInitUserInfo initUserInfo, IMapper mapper) : base(unitOfWork, initUserInfo)
        {
            _mapper = mapper;
        }

        public async Task<HelloWorldVM> InsertMysqlHelloWorld(HelloWorldCreateInput input)
        {
            var helloWorldTbl = _mapper.Map<hello_world_tbl>(input);
            var byIdAsync = await InsertReturnEntityAsync(helloWorldTbl);
            var helloWorldVm = _mapper.Map<HelloWorldVM>(byIdAsync);
            return helloWorldVm;
        }

        public async Task<HelloWorldVM> ReadMysqlHelloWorld(HelloWorldSearchInput input)
        {
            var byIdAsync = await GetByIdAsync(input.id);
            var helloWorldVm = _mapper.Map<HelloWorldVM>(byIdAsync);
            return helloWorldVm;
        }
    }
}